package huixue.cn.com.rxapp.kchart.adapter;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import huixue.cn.com.rxapp.kchart.bean.KLineData;
import huixue.cn.com.rxapp.widget.util.DateUtil;

/**
 * Created by gongdongyang 2019/7/24
 * Describe:
 */
public class KChartAdapter extends BaseKChartAdapter{

    private List<KLineData> datas = new ArrayList<>();

    public KChartAdapter() {

    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public Date getDate(int position) {
        try {
            String s = datas.get(position).getT()+"";
            //return DateUtil.getDateByByStringDate(s);
            return DateUtil.getDateByMillisecond(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public void addFooterData(List<KLineData> data) {
        if (data != null && !data.isEmpty()) {
            datas.addAll(0, data);
            notifyDataSetChanged();
        }
    }
}
